package com.example.task051;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

public class CalculateService extends Service {
    String TAG = "CalculateService:TAG:";
/*    private MyBinder myBinder = new MyBinder();
    class MyBinder extends Binder {
    }*/

    public CalculateService() {
    }

    /**
     * 服务的生命周期
     */
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public IBinder onBind(Intent intent) {
        return  myBinder;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public boolean onUnbind(Intent intent) {
        return super.onUnbind(intent);
    }
    /*private class CalculateServiceImpl extends IMyAidlInterface.Stub {

        @Override
        public double add(double a, double b) throws RemoteException {
            return a+b;
        }

        @Override
        public double subtract(double a, double b) throws RemoteException {
            return a-b;
        }

        @Override
        public double multiply(double a, double b) throws RemoteException {
            return a+b;
        }
    }*/

    //创建一个匿名内部类
    IMyAidlInterface.Stub myBinder = new IMyAidlInterface.Stub() {

        @Override
        public double add(double a, double b) throws RemoteException {
            return a+b;
        }

        @Override
        public double subtract(double a, double b) throws RemoteException {
            return a-b;
        }

        @Override
        public double multiply(double a, double b) throws RemoteException {
            return a*b;
        }
    };
}